<?php

namespace app\api\command;

use think\console\Command;
use think\console\Input;
use think\console\Output;
use app\common\model\Gupiao;
use app\common\model\GupiaoJihePrice;

/**
 * 数据分析
 * 通过分析昨天的股票数据及当天早上集合竞价的数据选出目标股票
 * Class GupiaoPrice
 * @package app\api\command
 * @author wangshenghong
 * @date 2024.07.22
 */
class GupiaoAnalysis extends Command{

    protected function configure(){
        $this->setName('GupiaoAnalysis')->setDescription('数据分析，获取想要的股票数据');
    }

    protected function execute(Input $input, Output $output){
        $date = date('Y-m-d H:i:s', 1732843714);
        $code = 600206;
        $name = '有研新材';
        echo "\n\r";
        echo "\n\r";
        echo "\n\r";
        echo '启动数据量化脚本'."\n\r";
        echo "=======".$date." start======="."\n\r";
        echo "处理结果code:{$code} name:$name"."\n\r";
        echo "=======".$date." end======="."\n\r";
        echo "\n\r";
        echo "\n\r";
        echo "\n\r";
        die;
        $field = 'name,symbol';
        $gupiaoList = collection(Gupiao::field($field)->select())->toArray();

        $field = 'price,timestamp';
        foreach ($gupiaoList as $item) {
//            print_r($item);die;
            $where = [
                ['symbol', '=', $item['symbol']],
                ['timestamp', '>=', strtotime(date('9:20'))]
            ];
            $priceList = collection(GupiaoJihePrice::field($field)->where('symbol', '=', $item['symbol'])->where('timestamp', '>=', strtotime(date('9:20')))->order('timestamp', 'desc')->select())->toArray();
            //判断价格是否递增
            for ($i = 1; $i < count($priceList); $i++) {
                if ($priceList[$i] >= $priceList[$i - 1]) {
                    continue; // 如果发现后续元素大于前一个，则不是递减序列
                }
            }
            //是一直递增的 或者 一直价格不变的
            echo $item['name'].$item['symbol']."\n\r";
        }
    }
}
